﻿using Furion.DataEncryption;
using Furion.DataEncryption.Extensions;
using Mapster;
using Mrhd.Core.Entities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Mrhd.Application
{
    /// <summary>
    /// mapster映射配置
    /// </summary>
    public class Mapper : IRegister
    {
        private string encrypKey = "jiandanmao";        // DESC加密密钥
        public void Register(TypeAdapterConfig config)
        {
            config.ForType<SystemEntity, SystemEntityDTO>()
                .Map(a => a.Id, a => DESCEncryption.Encrypt(a.Id.ToString(), encrypKey, true));

            config.ForType<SystemEntityDTO, SystemEntity>()
                .Map(a => a.Id, a => DESCEncryption.Decrypt(a.Id.ToString(), encrypKey, true));

            config.ForType<UserEntity, UserEntityDto>()
                .Map(a => a.Gender, a => a.Gender.ToString());

            config.ForType<ProductTypeEntity, ProductTypeDto>()
                .Map(a => a.Products, a => a.Products == null ? null : a.Products.Select(b => b.Adapt<ProductEntityDto>()));


        }

    }

}
